package com.zhangtai.modules.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangtai.modules.entity.employee.ReportBackInfoEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 *
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-12-11 16:09:07
 */
@Mapper
public interface ReportBackInfoDao extends BaseMapper<ReportBackInfoEntity> {

    @Select("<script>" +
            "Select r.* from tb_report_back_info r " +
            "left join tb_employee_info i on i.oid = r.oid " +
            "<where>   r.is_delete = 0 " +
//            "<if test='time!=null and time!=&apos;&apos;' >and r.operate_time &gt;= #{time} and r.operate_time &lt;=#{endTime} </if>" +
            "<if test='beginGmtCancel!=null and beginGmtCancel!=&apos;&apos;' >and r.begin_gmt_cancel &gt;= #{beginGmtCancel}  </if>" +
            "<if test='endGmtCancel!=null and endGmtCancel!=&apos;&apos;' >and  r.end_gmt_cancel &lt;=#{endGmtCancel} </if>" +

            "<if test='createtime!=null'>and r.createTime = #{createtime} </if>" +
            "<if test='orgName!=null and orgName!=&apos;&apos;'>and r.org_name like '%${orgName}%' </if>" +
            "<if test='unitName!=null and unitName!=&apos;&apos;'>and r.unit_name like '%${unitName}%' </if>" +
            "<if test='jobName!=null and jobName!=&apos;&apos;'>and r.job_name like '%${jobName}%' </if>" +
            "<if test='userName!=null and userName!=&apos;&apos;'>and r.user_name like '%${userName}%' </if>" +

            "<if test='orgIds!=null and orgIds.size>0'> and r.unit_id in " +
            " <foreach item=\"orgId\" index=\"index\" collection=\"orgIds\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach>" +
            "</if>"+

            "<if test='orgIds==null or orgIds.size==0'> and (r.unit_id = null or r.oid = #{oid}) </if>" +

            "</where>" +
//            " order by confirm_time desc" +
            "</script>")
    List<ReportBackInfoEntity> getReportAuth(
            @Param(value = "orgName") String orgName,
            @Param(value = "unitName") String unitName,
            @Param(value = "jobName") String jobName,
            @Param(value = "userName") String userName,
                                                @Param(value = "createtime") String createtime,
                                                   @Param(value = "orgIds") List<Long> orgIds,
                                                   @Param(value = "beginGmtCancel") String beginGmtCancel,
                                                   @Param(value = "endGmtCancel") String endGmtCancel,
                                                   Page<ReportBackInfoEntity> page);

}